package vip.xiaonuo.smzq.modular.kcl.controller;

import javax.annotation.Resource;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import vip.xiaonuo.smzq.modular.kcl.entity.Sjyj;
import vip.xiaonuo.smzq.modular.kcl.entity.vo.EarlyWarningTypeCount;
import vip.xiaonuo.smzq.modular.kcl.service.ISjyjService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import vip.xiaonuo.common.pojo.CommonResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;


/**
 * 矿山数据预警
 *
 * @author sqq
 * @since 2024-06-04
 */
@Api(tags = "矿山数据预警")
@RestController
@RequestMapping("/kcl/sjyj")
@Validated
public class SjyjController {

    @Resource
    private ISjyjService iSjyjService;

    /**
     * 添加矿山数据预警
     */
    @ApiOperation("添加矿山数据预警")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid Sjyj sjyj) {
        iSjyjService.save(sjyj);
        return CommonResult.ok();
    }

    /**
     * 删除矿山数据预警
     */
    @ApiOperation("删除矿山数据预警")
    @PostMapping("/delete")
    public CommonResult<String> delete(@ApiParam(name = "pkid", value = "主键") @RequestParam String pkid) {
        iSjyjService.removeById(pkid);
        return CommonResult.ok();
    }

    /**
     * 编辑矿山数据预警
     */
    @ApiOperation("编辑矿山数据预警")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Valid Sjyj sjyj) {
        iSjyjService.updateById(sjyj);
        return CommonResult.ok();
    }

    /**
     * 矿山数据预警分页查询
     */
    @ApiOperation("矿山数据预警分页查询")
    @GetMapping("/list")
    public CommonResult<Page<Sjyj>> page(@ApiParam(name = "current", value = "页数", example = "1", required = true) @RequestParam long current,
                                         @ApiParam(name = "size", value = "每页数量", example = "20", required = true) @RequestParam long size,
                                         @ApiParam(name = "nd", value = "年度") Integer nd,
                                         @ApiParam(name = "djflbh", value = "登记分类编号") Integer djflbh,
                                         @ApiParam(name = "kqbh", value = "矿区编号") String kqbh,
                                         @ApiParam(name = "xzqhdm", value = "行政区划") String xzqhdm,
                                         @ApiParam(name = "sjyjlxbm", value = "数据预警类型编码") Integer sjyjlxbm) {
        return CommonResult.data(iSjyjService.page(current, size, nd, xzqhdm, sjyjlxbm,djflbh,kqbh));
    }


    /**
     * 矿山数据预警各类型统计数量
     */
    @ApiOperation("矿山数据预警各类型统计数量")
    @GetMapping("/getEarlyWarningTypeCount")
    public CommonResult<EarlyWarningTypeCount> getEarlyWarningTypeCount(
                                                    @ApiParam(name = "nd", value = "年度") Integer nd,
                                                    @ApiParam(name = "djflbh", value = "登记分类编号") Integer djflbh,
                                                    @ApiParam(name = "kqbh", value = "矿区编号") String kqbh,
                                                    @ApiParam(name = "xzqhdm", value = "行政区划") String xzqhdm,
                                                    @ApiParam(name = "sjyjlxbm", value = "数据预警类型编码") Integer sjyjlxbm) {
        return CommonResult.data(iSjyjService.getEarlyWarningTypeCount(nd, xzqhdm, sjyjlxbm,djflbh,kqbh));
    }


    /**
     * 校验储量数据预警
     */
    @ApiOperation("校验储量数据预警")
    @PostMapping("/reservesDataEarlywarning")
    public CommonResult<String> reservesDataEarlywarning(String kqbh, Integer nd, Integer djflbh) {
        iSjyjService.reservesDataEarlywarning(kqbh, nd, djflbh);
        return CommonResult.ok();
    }

    /**
     * 同步某年的消息预警信息
     */
    @ApiOperation("同步某年的消息预警信息")
    @PostMapping("/synchronousMessageAlert")
    public CommonResult<String> synchronousMessageAlert(Integer nd) {
        iSjyjService.synchronousMessageAlert( nd);
        return CommonResult.ok();
    }




    @ApiOperation("矿山数据预警-导出Excel")
    @GetMapping("/exportKsyj")
    public void exportKsyj(
            @ApiParam(name = "nd", value = "年度") Integer nd,
            @ApiParam(name = "djflbh", value = "登记分类编号") Integer djflbh,
            @ApiParam(name = "kqbh", value = "矿区编号") String kqbh,
            @ApiParam(name = "xzqhdm", value = "行政区划") String xzqhdm,
            @ApiParam(name = "sjyjlxbm", value = "数据预警类型编码") Integer sjyjlxbm,
            HttpServletResponse response){

        response.setContentType("application/vnd.ms-excel");
        response.setHeader("ContentType", "application/vnd.ms-excel");
        response.setCharacterEncoding("UTF-8");

        iSjyjService.exportKsyj(nd, xzqhdm, sjyjlxbm,djflbh,kqbh,response);
    }

}